﻿Shader "Dan/UI/UI_RadialLine"
{
    Properties
    {
        _Color ("Color", Color) = (0.1137255,0.6666667,0.9568628,1)
        _Speed ("Speed", Float ) = 1
        _Density ("Density", Float ) = 128
        _Radius ("Radius", Range(0, 1)) = 0.33
        _Emission ("Emission", Float ) = 1
        _Length ("Length", Float ) = 1.5
        _Amount ("Amount", Range(0, 1)) = 0.5
        _Width ("Width", Range(0, 1)) = 0.5

    }
    
    SubShader
    {

        Tags { "IgnoreProjector"="True"
            "Queue"="Transparent"
            "RenderType"="Transparent" }
        LOD 100    
        Blend SrcAlpha OneMinusSrcAlpha
        ZWrite Off 
 
        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            
            #include "UnityCG.cginc"
            #include "../ShaderLibs/UIFX.cginc"
            #include "../ShaderLibs/UVOperator.cginc"
            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };
            
            struct v2f
            {
                float4 vertex : SV_POSITION;    
                float2 uv : TEXCOORD0;
                
            };

             float _Speed;
             float4 _Color;
             float _Density;
             float _Radius;
             float _Emission;
             float _Length;
             float _Amount;
             float _Width;
            
            v2f vert ( appdata v )
            {
                
                v2f o;
                UNITY_INITIALIZE_OUTPUT(v2f ,o);
                o.vertex = UnityObjectToClipPos(v.vertex);
                
                o.uv = v.uv;        
                return o;
            }
            
            


            fixed4 frag (v2f i ) : SV_Target
            {
                
                
                float2 uv = i.uv;
                float3 emissive = (_Color.rgb*_Emission);
                float3 finalColor = emissive;
                float2 puv = (uv*2.0-1.0);
                float circle = length(puv);
                float polar = DrawPolar(puv);
                float polarFrac = step(_Width,frac(polar*_Density));
                

                float denstiy = floor(polar * _Density) / (_Density - 1);
                float ts1 = _Time.y*_Speed*0.0001;
                float2 rd1 = float2((denstiy+ts1),denstiy);
                float ts2 = denstiy+(ts1/10);
                float2 rd2 = float2(ts2,ts2);

                float radialNoise01 = Flick(rd1);
                float radialNoise02 = Flick(rd2);
                float sLine =frac(circle/max(_Length,0)-radialNoise01-_Time.y*_Speed);
                sLine = saturate(sLine)-0.5;
                sLine =saturate(sLine*sLine*4.0);
                
                
                float radiusMask =smoothstep(0.5, 1, circle-(_Radius*2-1) );
                float radomLine =step(_Amount,radialNoise02*polarFrac);

                return fixed4(finalColor,sLine*polarFrac*radiusMask*radomLine);
                
            }
            ENDCG
        }
    }
    
    
    
}
